import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './index'
import el from "element-ui/src/locale/lang/el"
Vue.use(VueRouter)

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})


router.beforeEach((to, from, next) => {
    document.title = to.meta.title || '后台管理系统'
    const token = localStorage.getItem('token')
    if(to.meta.requiresAuth===true){
       if (token) {
           next()
       }else{
           Vue.prototype.$message.error('请先登录')
           next({
               path: '/login'
           })
       }
    }else {
        next()
    }
})
export default router
